package com.koron.order.overhaul.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.system.staff.vo.EamUser;
import com.koron.common.core.annocation.CasUser;
import com.koron.order.overhaul.bean.entity.OverhaulOrderBean;
import com.koron.order.overhaul.bean.query.OverhaulOrderQuery;
import com.koron.order.overhaul.bean.vo.OverhaulOrderDetailVO;
import com.koron.order.overhaul.bean.vo.OverhaulOrderMajorFormVO;
import com.koron.order.overhaul.service.MobileOverhaulOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author twcao
 * @title: MobileOverhaulOrderController
 * @projectName GDH_EAM_V2
 * @description: 移动大修工单
 * @date 2021/11/1116:40
 */
@Slf4j
@Api(tags = "大修工单-mobile")
@RestController
@RequestMapping("/mobile/overhaul")
public class MobileOverhaulOrderController {

    @Autowired
    private MobileOverhaulOrderService mobileOverhaulOrderService;

    @ApiOperation(value = "根据大修工单id查询详情")
    @GetMapping("queryById")
    @ApiParam(name = "id", value = "大修工单id")
    public Response<OverhaulOrderDetailVO> queryById(@CasUser @ApiIgnore EamUser user, String id) {
        log.info("[mobile]大修工单详情查询， id = {}", id);
        return Response.ok("查询成功", ADOConnection.runTask(user.getCurrDs(), mobileOverhaulOrderService, "queryById", OverhaulOrderDetailVO.class, id));
    }

    @ApiOperation(value = "查询列表")
    @GetMapping("queryList")
    public Response<PageInfo<OverhaulOrderBean>> queryList(@CasUser @ApiIgnore EamUser user, OverhaulOrderQuery query) {
        log.info("[mobile]大修工单列表查询，query = {}", JSON.toJSONString(query));
        PageHelper.startPage(query.getPage(), query.getPageSize(), query.getOrderBy());
        List list = ADOConnection.runTask(user.getCurrDs(), mobileOverhaulOrderService, "queryList", List.class, query);
        return Response.ok("查询成功", new PageInfo<>(list));
    }

    @ApiOperation(value = "执行中(status = 3)，新增或修改(表单,作业过程)，返回表单id")
    @PostMapping("/saveOrUpdate")
    public Response<String> execute(@CasUser @ApiIgnore EamUser user, @RequestBody List<OverhaulOrderMajorFormVO> vos) {
        log.info("[mobile]执行中-新增或修改(表单,作业过程)，vo = {}", JSON.toJSONString(vos));
        return Response.ok("操作成功", ADOConnection.runTask(user.getCurrDs(), mobileOverhaulOrderService, "executeSaveOrUpdate", String.class, vos));
    }

    @ApiOperation(value = "提交")
    @PostMapping("/submit")
    public Response<String> submit(@CasUser @ApiIgnore EamUser user, @RequestBody OverhaulOrderBean bean) {
        return Response.ok("操作成功", ADOConnection.runTask(user.getCurrDs(), mobileOverhaulOrderService, "updateStatus", String.class, bean));
    }
}
